home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MPW_TOOL / TOOLS / TOOLS_WI / ICON_8 / ICONX_FO / RDEBUG.C < prev    next >
Text File  |  1990-03-02  |  6KB  |  275 lines

  1. /*
  2.  * rdebug.c - breakpoint, variable, ttrace, xtrace.
  3.  */
  4.  
  5. #include <math.h>
  6. #include "::h:config.h"
  7. #include "::h:rt.h"
  8. #include "rproto.h"
  9. #include "::h:opdefs.h"
  10.  
  11.  
  12. #ifdef TraceBack
  13. extern struct b_list list_tmp;        /* argument of Op_Apply */
  14. extern struct b_proc *opblks[];
  15. extern word lastop;            /* last op-code */
  16. extern dptr xargp;
  17. extern word xnargs;            /* number of arguments */
  18. extern dptr fnames;
  19. #endif                    /* TraceBack */
  20.  
  21.  
  22. #ifdef TraceBack
  23. /*
  24.  * ttrace - show offending expression.
  25.  */
  26. novalue ttrace()
  27.    {
  28.    struct b_proc *bp;
  29.    word nargs;
  30.  
  31.    fprintf(stderr, "   ");
  32.  
  33.    switch ((int)lastop) {
  34.  
  35.       case Op_Invoke:
  36.          bp = (struct b_proc *)BlkLoc(*xargp);
  37.          nargs = xnargs;
  38.          if (xargp[0].dword == D_Proc)
  39.             putstr(stderr, &(bp->pname));
  40.          else
  41.             outimage(stderr, xargp, 0);
  42.          putc('(', stderr);
  43.          while (nargs--) {
  44.             outimage(stderr, ++xargp, 0);
  45.             if (nargs)
  46.                putc(',', stderr);
  47.             }
  48.          putc(')', stderr);
  49.          break;
  50.  
  51.       case Op_Toby:
  52.          putc('{', stderr);
  53.          outimage(stderr, ++xargp, 0);
  54.          fprintf(stderr, " to ");
  55.          outimage(stderr, ++xargp, 0);
  56.          fprintf(stderr, " by ");
  57.          outimage(stderr, ++xargp, 0);
  58.          putc('}', stderr);
  59.          break;
  60.  
  61.       case Op_Subsc:
  62.          putc('{', stderr);
  63.          outimage(stderr, ++xargp, 0);
  64.          putc('[', stderr);
  65.          outimage(stderr, ++xargp, 0);
  66.          putc(']', stderr);
  67.          putc('}', stderr);
  68.          break;
  69.  
  70.       case Op_Sect:
  71.          putc('{', stderr);
  72.          outimage(stderr, ++xargp, 0);
  73.          putc('[', stderr);
  74.          outimage(stderr, ++xargp, 0);
  75.          putc(':', stderr);
  76.          outimage(stderr, ++xargp, 0);
  77.          putc(']', stderr);
  78.          putc('}', stderr);
  79.          break;
  80.  
  81.       case Op_Bscan:
  82.          putc('{', stderr);
  83.          outimage(stderr, xargp, 0);
  84.          fputs(" ? ..}", stderr);
  85.          break;
  86.  
  87.       case Op_Coact:
  88.          putc('{', stderr);
  89.          outimage(stderr, ++xargp, 0);
  90.          fprintf(stderr, " @ ");
  91.          outimage(stderr, ++xargp, 0);
  92.          putc('}', stderr);
  93.          break;
  94.  
  95.       case Op_Apply:
  96.          outimage(stderr, xargp++, 0);
  97.          fprintf(stderr," ! ");
  98.          outimage(stderr, (dptr)&list_tmp, 0);
  99.          break;
  100.  
  101.       case Op_Create:
  102.          fprintf(stderr,"{create ..}");
  103.          break;
  104.  
  105.       case Op_Field:
  106.          putc('{', stderr);
  107.          outimage(stderr, ++xargp, 0);
  108.          fprintf(stderr, " . ");
  109.          fprintf(stderr, "%s", StrLoc(fnames[IntVal(*++xargp)]));
  110.          putc('}', stderr);
  111.          break;
  112.  
  113.       case Op_Limit:
  114.          fprintf(stderr, "limit counter: ");
  115.          outimage(stderr, xargp, 0);
  116.          break;
  117.  
  118.       case Op_Llist:
  119.          fprintf(stderr,"[ ... ]");
  120.          break;
  121.  
  122.    
  123.       default:
  124.          bp = opblks[lastop];
  125.          nargs = abs((int)bp->nparam);
  126.          putc('{', stderr);
  127.          if (lastop == Op_Bang || lastop == Op_Random)
  128.             goto oneop;
  129.          if (abs((int)bp->nparam) >= 2) {
  130.             outimage(stderr, ++xargp, 0);
  131.             putc(' ', stderr);
  132.             putstr(stderr, &(bp->pname));
  133.             putc(' ', stderr);
  134.            }
  135.          else
  136. oneop:
  137.          putstr(stderr, &(bp->pname));
  138.          outimage(stderr, ++xargp, 0);
  139.          putc('}', stderr);
  140.       }
  141.      
  142.    if (ipc.opnd != NULL)
  143.       fprintf(stderr, " from line %d in %s", findline(ipc.opnd),
  144.          findfile(ipc.opnd));
  145.    putc('\n', stderr);
  146.    fflush(stderr);
  147.    }
  148.  
  149. /*
  150.  * xtrace - procedure *bp is being called with nargs arguments, the first
  151.  *  of which is at arg; produce a trace message.
  152.  */
  153. novalue xtrace(bp, nargs, arg, pline, pfile)
  154. struct b_proc *bp;
  155. word nargs;
  156. dptr arg;
  157. int pline;
  158. char *pfile;
  159.    {
  160.  
  161.    fprintf(stderr, "   ");
  162.    if (bp == NULL)
  163.       fprintf(stderr, "????");
  164.  
  165.    else {
  166.          if (arg[0].dword == D_Proc)
  167.             putstr(stderr, &(bp->pname));
  168.          else
  169.             outimage(stderr, arg, 0);
  170.          arg++;
  171.          putc('(', stderr);
  172.          while (nargs--) {
  173.             outimage(stderr, arg++, 0);
  174.             if (nargs)
  175.                putc(',', stderr);
  176.             }
  177.          putc(')', stderr);
  178.       }
  179.      
  180.    if (pline != 0)
  181.       fprintf(stderr, " from line %d in %s", pline, pfile);
  182.    putc('\n', stderr);
  183.    fflush(stderr);
  184.    }
  185. #endif                     /* TraceBack */
  186.  
  187. /*
  188.  * Service routine to display variables in given number of
  189.  *  procedure calls to file f.
  190.  */
  191.  
  192. novalue xdisp(fp,dp,count,f)
  193.    int count;
  194.    FILE *f;
  195.    struct pf_marker *fp;
  196.    register dptr dp;
  197.    {
  198.    register dptr np;
  199.    register int n;
  200.    struct b_proc *bp;
  201.    extern dptr globals, eglobals;
  202.    extern dptr gnames;
  203.    extern dptr statics;
  204.  
  205.    while (count--) {        /* go back through 'count' frames */
  206.  
  207.       bp = (struct b_proc *)BlkLoc(*dp); /* get address of procedure block */
  208.  
  209.       /*
  210.        * Print procedure name.
  211.        */
  212.       putstr(f, &(bp->pname));
  213.       fprintf(f, " local identifiers:\n");
  214.  
  215.       /*
  216.        * Print arguments.
  217.        */
  218.       np = bp->lnames;
  219.       for (n = abs(bp->nparam); n > 0; n--) {
  220.          fprintf(f, "   ");
  221.          putstr(f, np);
  222.          fprintf(f, " = ");
  223.          outimage(f, ++dp, 0);
  224.          putc('\n', f);
  225.          np++;
  226.          }
  227.  
  228.       /*
  229.        * Print locals.
  230.        */
  231.       dp = &fp->pf_locals[0];
  232.       for (n = (int)bp->ndynam; n > 0; n--) {
  233.          fprintf(f, "   ");
  234.          putstr(f, np);
  235.          fprintf(f, " = ");
  236.          outimage(f, dp++, 0);
  237.          putc('\n', f);
  238.          np++;
  239.          }
  240.  
  241.       /*
  242.        * Print statics.
  243.        */
  244.       dp = &statics[bp->fstatic];
  245.       for (n = (int)bp->nstatic; n > 0; n--) {
  246.          fprintf(f, "   ");
  247.          putstr(f, np);
  248.          fprintf(f, " = ");
  249.          outimage(f, dp++, 0);
  250.          putc('\n', f);
  251.          np++;
  252.          }
  253.  
  254.       dp = fp->pf_argp;
  255.       fp = fp->pf_pfp;
  256.       }
  257.  
  258.    /*
  259.     * Print globals.
  260.     */
  261.    fprintf(f, "\nglobal identifiers:\n");
  262.    dp = globals;
  263.    np = gnames;
  264.    while (dp < eglobals) {
  265.       fprintf(f, "   ");
  266.       putstr(f, np);
  267.       fprintf(f, " = ");
  268.       outimage(f, dp++, 0);
  269.       putc('\n', f);
  270.       np++;
  271.       }
  272.    fflush(f);
  273.    }
  274.  
  275.